How we selected the Best Map

Initially we started with a Shape file, ggplot and ggplotly() function


  • Points on visuals here

We used ‘usmap’ package, ggplot and ggplotly() function


Points here

Used the Plotly package for chlopleth plots using plot_geo()


My Points here

  • Point 1

  • Point 2

  • Point 3

Tried Leaflet


Points here

Leaflet Legend Issue


Points here

Final Plot we selected for Shiny


My Points here

  • Point 1

  • Point 2

  • Point 3

Tab 3

Tab 3 Slide 1

Visuals here


Points here

Tab 3 Slide 2

Visuals Here


Points here

Tab 3 Slide 3

Visuals here


Points here

Tab 3 Slide 4

Visuals here


Points here

Conclusion

THANK YOU!!

Thank You


Our GitHub repo:

Our Rpubs link:

Shiny app link:

THANK YOU!!

---
title: "Foster Care Project Presentation"
output: 
  flexdashboard::flex_dashboard:
    source_code: embed
    theme: spacelab
    social: [ "twitter", "facebook", "menu" ]
---

```{r message=FALSE, warning=FALSE, include=FALSE}
library(flexdashboard)
library(readxl)
library(tidyverse)
library(viridis)
library(plotly)
library(sf)
library(leaflet)
```

```{r load-data-transformation}
#national dataset
nation_data<-read_excel("data/national_afcars_trends_2009_through_2018.xlsx",sheet="Data")

#State dataset
#Numbers of Children Served in Foster Care, by State
state_served <- read_excel("data/afcars_state_data_tables_09thru18.xlsx",range="Served!A8:K60") %>%
gather(year,Served,'FY 2009':'FY 2018')

#Numbers of Children in Foster Care on September 30th, by State
state_inCare <- read_excel("data/afcars_state_data_tables_09thru18.xlsx",range="In Care on September 30th!A8:K60") %>%
gather(year,InCare_Sep30,'FY 2009':'FY 2018')

#Numbers of Children Entering Foster Care, by State
state_entered <- read_excel("data/afcars_state_data_tables_09thru18.xlsx",range="Entered!A8:K60") %>%
gather(year,Entered,'FY 2009':'FY 2018')

#Numbers of Children Exiting Foster Care, by State
state_exited <- read_excel("data/afcars_state_data_tables_09thru18.xlsx",range="Exited!A8:K60") %>%
gather(year,Exited,'FY 2009':'FY 2018')

#Numbers of Children Waiting for Adoption, by State
state_waitingAdoption <- read_excel("data/afcars_state_data_tables_09thru18.xlsx",range="Waiting for Adoption!A8:K60") %>%
gather(year,Waiting_Adoption,'FY 2009':'FY 2018')

#Numbers of Children Waiting for Adoption Whose Parental Rights Have Been Terminated, by State
state_parentalRightsTerminated <- read_excel("data/afcars_state_data_tables_09thru18.xlsx",range="Parental Rights Terminated!A8:K60") %>%
gather(year,parental_rights_terminated,'FY 2009':'FY 2018')

#Numbers of Children Adopted, by State
state_adopted <- read_excel("data/afcars_state_data_tables_09thru18.xlsx",range="Adopted!A8:K60") %>%
gather(year,adopted,'FY 2009':'FY 2018')
```

```{r merge_data}
merge_cols<-c("State","year")
#The merge argument only takes two values as input, so you have to do them separately:
#state_df<- merge(state_served,state_inCare,state_entered,state_exited,state_waitingAdoption,state_parentalRightsTerminated,state_adopted,by=c("State","year"))

state_data<- merge(state_served,state_inCare,by=merge_cols)
state_data<- merge(state_data,state_entered,by=merge_cols)
state_data<- merge(state_data,state_exited,by=merge_cols)
state_data<- merge(state_data,state_waitingAdoption,by=merge_cols)
state_data<- merge(state_data,state_parentalRightsTerminated,by=merge_cols)
state_data<- merge(state_data,state_adopted,by=merge_cols)
```

```{r message=FALSE, warning=FALSE, include=FALSE}
us_states <- st_read("./shp/states.shp")
```

```{r}
state_data_2009 <- state_data %>% filter(year == 'FY 2009') %>% rename(STATE_NAME = State)
```

```{r message=FALSE, warning=FALSE}
us_states_mapped <- inner_join(us_states,state_data_2009,by="STATE_NAME")
```


How we selected the Best Map{.storyboard}
=========================================


### Initially we started with a Shape file, ggplot and ggplotly() function

```{r message=FALSE, warning=FALSE}
g <- us_states_mapped %>%
  ggplot() +
  geom_sf(aes(fill = Served,text = paste0("State: ",STATE_NAME,", Year : ", year))) +
  # coord_sf(crs = st_crs(102003)) +
  scale_fill_viridis("Served",begin = 0.06,end=0.95,option = "plasma") +
  ggtitle("Orphans Served by each state in 2009") +
  theme_minimal() +
  theme(legend.position = "bottom",
        axis.text.x=element_blank(),
        axis.text.y=element_blank(),
        axis.ticks.x=element_blank(),
        axis.ticks.y=element_blank(),
        panel.grid.major = element_blank())
ggplotly(g,tooltip = c("text","fill"))
```

***

- Points on visuals here

### We used 'usmap' package, ggplot and ggplotly() function


```{r}
state_data_2009 <- us_states_mapped %>% rename(state = STATE_NAME)

g1 <- usmap::plot_usmap(data = state_data_2009,values = "Served") +
  scale_fill_viridis("Served",begin = 0.06,end=0.8,option = "plasma") +
  ggtitle("Orphans Served by each state in 2009") +
  theme_minimal() +
  theme(legend.position = "bottom",
        legend.title=element_text(size=10), 
        legend.text=element_text(size=5))


ggplotly(g1)
```


***

Points here


### Used the Plotly package for chlopleth plots using plot_geo()

```{r message=FALSE, warning=FALSE}

#Set hover text
us_states_mapped$hover <- with(us_states_mapped,paste(STATE_NAME,'
',"Served: ", Served)) # give state boundaries a white border l <- list(color = toRGB("white"), width = 2) # specify some map projection/options g2 <- list( scope = 'usa', projection = list(type = 'albers usa'), showlakes = TRUE, lakecolor = toRGB('white') ) g3 <- plot_geo(us_states_mapped, locationmode = 'USA-states') %>% add_trace( z = ~Served, text = ~hover, locations = ~STATE_ABBR, color = ~Served, colors = viridis_pal(option = "D")(3) ) %>% colorbar(title = "Served") %>% layout( title = 'Orphans Served by each state in 2009
(Hover for breakdown)', geo = g2 ) g3 ``` *** My Points here - Point 1 - Point 2 - Point 3 ### Tried Leaflet ```{r} popup1 <- paste0("US State Values", "
State: ", us_states_mapped$STATE_NAME, "
Served: ", us_states_mapped$Served) pal <- leaflet::colorFactor(viridis_pal(option = "D")(3), domain = us_states_mapped$Served) g4 <- leaflet(us_states_mapped) %>% addProviderTiles("OpenStreetMap.Mapnik") %>% addPolygons(data = us_states_mapped, fillColor = ~pal(Served), fillOpacity = 0.9, color = "darkgrey", weight = 1.5, popup = popup1) g4 ``` *** Points here ### Leaflet Legend Issue ```{r} popup1 <- paste0("US State Values", "
State: ", us_states_mapped$STATE_NAME, "
Served: ", us_states_mapped$Served) pal <- leaflet::colorFactor(viridis_pal(option = "D")(3), domain = us_states_mapped$Served) g5 <- leaflet(us_states_mapped) %>% addProviderTiles("OpenStreetMap.Mapnik") %>% addPolygons(data = us_states_mapped, fillColor = ~pal(Served), fillOpacity = 0.9, color = "darkgrey", weight = 1.5, popup = popup1) %>% addLegend(pal = pal, values = ~Served, opacity = 0.7, title = NULL, position = "bottomright") g5 ``` *** Points here ### Final Plot we selected for Shiny ```{r message=FALSE, warning=FALSE} #Set hover text us_states_mapped$hover <- with(us_states_mapped,paste(STATE_NAME,'
',"Served: ", Served)) # give state boundaries a white border l <- list(color = toRGB("white"), width = 2) # specify some map projection/options g6 <- list( scope = 'usa', projection = list(type = 'albers usa'), showlakes = TRUE, lakecolor = toRGB('white') ) g7 <- plot_geo(us_states_mapped, locationmode = 'USA-states') %>% add_trace( z = ~Served, text = ~hover, locations = ~STATE_ABBR, color = ~Served, colors = viridis_pal(option = "D")(3) ) %>% colorbar(title = "Served") %>% layout( title = 'Orphans Served by each state in 2009
(Hover for breakdown)', geo = g6 ) g7 ``` *** My Points here - Point 1 - Point 2 - Point 3 Tab 3 {.storyboard} ========================================= ### Tab 3 Slide 1 Visuals here *** Points here ### Tab 3 Slide 2 Visuals Here *** Points here ### Tab 3 Slide 3 Visuals here *** Points here ### Tab 3 Slide 4 Visuals here *** Points here Conclusion {.storyboard} ========================================= ### THANK YOU!! Thank You *** Our GitHub repo: Our Rpubs link: Shiny app link: THANK YOU!!